package org.hl7.fhir.dstu2.model;

/*
  Copyright (c) 2011+, HL7, Inc.
  All rights reserved.
  
  Redistribution and use in source and binary forms, with or without modification, 
  are permitted provided that the following conditions are met:
  
   * Redistributions of source code must retain the above copyright notice, this 
     list of conditions and the following disclaimer.
   * Redistributions in binary form must reproduce the above copyright notice, 
     this list of conditions and the following disclaimer in the documentation 
     and/or other materials provided with the distribution.
   * Neither the name of HL7 nor the names of its contributors may be used to 
     endorse or promote products derived from this software without specific 
     prior written permission.
  
  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
  IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
  POSSIBILITY OF SUCH DAMAGE.
  
*/

// Generated on Wed, Jul 13, 2016 05:32+1000 for FHIR v1.0.2
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.hl7.fhir.dstu2.model.Enumerations.RemittanceOutcome;
import org.hl7.fhir.dstu2.model.Enumerations.RemittanceOutcomeEnumFactory;
import ca.uhn.fhir.model.api.annotation.Child;
import ca.uhn.fhir.model.api.annotation.Description;
import ca.uhn.fhir.model.api.annotation.ResourceDef;
import ca.uhn.fhir.model.api.annotation.SearchParamDefinition;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.utilities.Utilities;

/**
 * This resource provides: the claim details; adjudication details from the
 * processing of a Claim; and optionally account balance information, for
 * informing the subscriber of the benefits provided.
 */
@ResourceDef(name = "ExplanationOfBenefit", profile = "http://hl7.org/fhir/Profile/ExplanationOfBenefit")
public class ExplanationOfBenefit extends DomainResource {

  /**
   * The Response business identifier.
   */
  @Child(name = "identifier", type = {
      Identifier.class }, order = 0, min = 0, max = Child.MAX_UNLIMITED, modifier = false, summary = true)
  @Description(shortDefinition = "Business Identifier", formalDefinition = "The Response business identifier.")
  protected List<Identifier> identifier;

  /**
   * Original request resource reference.
   */
  @Child(name = "request", type = { Claim.class }, order = 1, min = 0, max = 1, modifier = false, summary = true)
  @Description(shortDefinition = "Claim reference", formalDefinition = "Original request resource reference.")
  protected Reference request;

  /**
   * The actual object that is the target of the reference (Original request
   * resource reference.)
   */
  protected Claim requestTarget;

  /**
   * Transaction status: error, complete.
   */
  @Child(name = "outcome", type = { CodeType.class }, order = 2, min = 0, max = 1, modifier = false, summary = true)
  @Description(shortDefinition = "complete | error", formalDefinition = "Transaction status: error, complete.")
  protected Enumeration<RemittanceOutcome> outcome;

  /**
   * A description of the status of the adjudication.
   */
  @Child(name = "disposition", type = {
      StringType.class }, order = 3, min = 0, max = 1, modifier = false, summary = true)
  @Description(shortDefinition = "Disposition Message", formalDefinition = "A description of the status of the adjudication.")
  protected StringType disposition;

  /**
   * The version of the style of resource contents. This should be mapped to the
   * allowable profiles for this and supporting resources.
   */
  @Child(name = "ruleset", type = { Coding.class }, order = 4, min = 0, max = 1, modifier = false, summary = true)
  @Description(shortDefinition = "Resource version", formalDefinition = "The version of the style of resource contents. This should be mapped to the allowable profiles for this and supporting resources.")
  protected Coding ruleset;

  /**
   * The style (standard) and version of the original material which was converted
   * into this resource.
   */
  @Child(name = "originalRuleset", type = {
      Coding.class }, order = 5, min = 0, max = 1, modifier = false, summary = true)
  @Description(shortDefinition = "Original version", formalDefinition = "The style (standard) and version of the original material which was converted into this resource.")
  protected Coding originalRuleset;

  /**
   * The date when the enclosed suite of services were performed or completed.
   */
  @Child(name = "created", type = { DateTimeType.class }, order = 6, min = 0, max = 1, modifier = false, summary = true)
  @Description(shortDefinition = "Creation date", formalDefinition = "The date when the enclosed suite of services were performed or completed.")
  protected DateTimeType created;

  /**
   * The Insurer who produced this adjudicated response.
   */
  @Child(name = "organization", type = {
      Organization.class }, order = 7, min = 0, max = 1, modifier = false, summary = true)
  @Description(shortDefinition = "Insurer", formalDefinition = "The Insurer who produced this adjudicated response.")
  protected Reference organization;

  /**
   * The actual object that is the target of the reference (The Insurer who
   * produced this adjudicated response.)
   */
  protected Organization organizationTarget;

  /**
   * The practitioner who is responsible for the services rendered to the patient.
   */
  @Child(name = "requestProvider", type = {
      Practitioner.class }, order = 8, min = 0, max = 1, modifier = false, summary = true)
  @Description(shortDefinition = "Responsible practitioner", formalDefinition = "The practitioner who is responsible for the services rendered to the patient.")
  protected Reference requestProvider;

  /**
   * The actual object that is the target of the reference (The practitioner who
   * is responsible for the services rendered to the patient.)
   */
  protected Practitioner requestProviderTarget;

  /**
   * The organization which is responsible for the services rendered to the
   * patient.
   */
  @Child(name = "requestOrganization", type = {
      Organization.class }, order = 9, min = 0, max = 1, modifier = false, summary = true)
  @Description(shortDefinition = "Responsible organization", formalDefinition = "The organization which is responsible for the services rendered to the patient.")
  protected Reference requestOrganization;

  /**
   * The actual object that is the target of the reference (The organization which
   * is responsible for the services rendered to the patient.)
   */
  protected Organization requestOrganizationTarget;

  private static final long serialVersionUID = 205412587L;

  /*
   * Constructor
   */
  public ExplanationOfBenefit() {
    super();
  }

  /**
   * @return {@link #identifier} (The Response business identifier.)
   */
  public List<Identifier> getIdentifier() {
    if (this.identifier == null)
      this.identifier = new ArrayList<Identifier>();
    return this.identifier;
  }

  public boolean hasIdentifier() {
    if (this.identifier == null)
      return false;
    for (Identifier item : this.identifier)
      if (!item.isEmpty())
        return true;
    return false;
  }

  /**
   * @return {@link #identifier} (The Response business identifier.)
   */
  // syntactic sugar
  public Identifier addIdentifier() { // 3
    Identifier t = new Identifier();
    if (this.identifier == null)
      this.identifier = new ArrayList<Identifier>();
    this.identifier.add(t);
    return t;
  }

  // syntactic sugar
  public ExplanationOfBenefit addIdentifier(Identifier t) { // 3
    if (t == null)
      return this;
    if (this.identifier == null)
      this.identifier = new ArrayList<Identifier>();
    this.identifier.add(t);
    return this;
  }

  /**
   * @return {@link #request} (Original request resource reference.)
   */
  public Reference getRequest() {
    if (this.request == null)
      if (Configuration.errorOnAutoCreate())
        throw new Error("Attempt to auto-create ExplanationOfBenefit.request");
      else if (Configuration.doAutoCreate())
        this.request = new Reference(); // cc
    return this.request;
  }

  public boolean hasRequest() {
    return this.request != null && !this.request.isEmpty();
  }

  /**
   * @param value {@link #request} (Original request resource reference.)
   */
  public ExplanationOfBenefit setRequest(Reference value) {
    this.request = value;
    return this;
  }

  /**
   * @return {@link #request} The actual object that is the target of the
   *         reference. The reference library doesn't populate this, but you can
   *         use it to hold the resource if you resolve it. (Original request
   *         resource reference.)
   */
  public Claim getRequestTarget() {
    if (this.requestTarget == null)
      if (Configuration.errorOnAutoCreate())
        throw new Error("Attempt to auto-create ExplanationOfBenefit.request");
      else if (Configuration.doAutoCreate())
        this.requestTarget = new Claim(); // aa
    return this.requestTarget;
  }

  /**
   * @param value {@link #request} The actual object that is the target of the
   *              reference. The reference library doesn't use these, but you can
   *              use it to hold the resource if you resolve it. (Original request
   *              resource reference.)
   */
  public ExplanationOfBenefit setRequestTarget(Claim value) {
    this.requestTarget = value;
    return this;
  }

  /**
   * @return {@link #outcome} (Transaction status: error, complete.). This is the
   *         underlying object with id, value and extensions. The accessor
   *         "getOutcome" gives direct access to the value
   */
  public Enumeration<RemittanceOutcome> getOutcomeElement() {
    if (this.outcome == null)
      if (Configuration.errorOnAutoCreate())
        throw new Error("Attempt to auto-create ExplanationOfBenefit.outcome");
      else if (Configuration.doAutoCreate())
        this.outcome = new Enumeration<RemittanceOutcome>(new RemittanceOutcomeEnumFactory()); // bb
    return this.outcome;
  }

  public boolean hasOutcomeElement() {
    return this.outcome != null && !this.outcome.isEmpty();
  }

  public boolean hasOutcome() {
    return this.outcome != null && !this.outcome.isEmpty();
  }

  /**
   * @param value {@link #outcome} (Transaction status: error, complete.). This is
   *              the underlying object with id, value and extensions. The
   *              accessor "getOutcome" gives direct access to the value
   */
  public ExplanationOfBenefit setOutcomeElement(Enumeration<RemittanceOutcome> value) {
    this.outcome = value;
    return this;
  }

  /**
   * @return Transaction status: error, complete.
   */
  public RemittanceOutcome getOutcome() {
    return this.outcome == null ? null : this.outcome.getValue();
  }

  /**
   * @param value Transaction status: error, complete.
   */
  public ExplanationOfBenefit setOutcome(RemittanceOutcome value) {
    if (value == null)
      this.outcome = null;
    else {
      if (this.outcome == null)
        this.outcome = new Enumeration<RemittanceOutcome>(new RemittanceOutcomeEnumFactory());
      this.outcome.setValue(value);
    }
    return this;
  }

  /**
   * @return {@link #disposition} (A description of the status of the
   *         adjudication.). This is the underlying object with id, value and
   *         extensions. The accessor "getDisposition" gives direct access to the
   *         value
   */
  public StringType getDispositionElement() {
    if (this.disposition == null)
      if (Configuration.errorOnAutoCreate())
        throw new Error("Attempt to auto-create ExplanationOfBenefit.disposition");
      else if (Configuration.doAutoCreate())
        this.disposition = new StringType(); // bb
    return this.disposition;
  }

  public boolean hasDispositionElement() {
    return this.disposition != null && !this.disposition.isEmpty();
  }

  public boolean hasDisposition() {
    return this.disposition != null && !this.disposition.isEmpty();
  }

  /**
   * @param value {@link #disposition} (A description of the status of the
   *              adjudication.). This is the underlying object with id, value and
   *              extensions. The accessor "getDisposition" gives direct access to
   *              the value
   */
  public ExplanationOfBenefit setDispositionElement(StringType value) {
    this.disposition = value;
    return this;
  }

  /**
   * @return A description of the status of the adjudication.
   */
  public String getDisposition() {
    return this.disposition == null ? null : this.disposition.getValue();
  }

  /**
   * @param value A description of the status of the adjudication.
   */
  public ExplanationOfBenefit setDisposition(String value) {
    if (Utilities.noString(value))
      this.disposition = null;
    else {
      if (this.disposition == null)
        this.disposition = new StringType();
      this.disposition.setValue(value);
    }
    return this;
  }

  /**
   * @return {@link #ruleset} (The version of the style of resource contents. This
   *         should be mapped to the allowable profiles for this and supporting
   *         resources.)
   */
  public Coding getRuleset() {
    if (this.ruleset == null)
      if (Configuration.errorOnAutoCreate())
        throw new Error("Attempt to auto-create ExplanationOfBenefit.ruleset");
      else if (Configuration.doAutoCreate())
        this.ruleset = new Coding(); // cc
    return this.ruleset;
  }

  public boolean hasRuleset() {
    return this.ruleset != null && !this.ruleset.isEmpty();
  }

  /**
   * @param value {@link #ruleset} (The version of the style of resource contents.
   *              This should be mapped to the allowable profiles for this and
   *              supporting resources.)
   */
  public ExplanationOfBenefit setRuleset(Coding value) {
    this.ruleset = value;
    return this;
  }

  /**
   * @return {@link #originalRuleset} (The style (standard) and version of the
   *         original material which was converted into this resource.)
   */
  public Coding getOriginalRuleset() {
    if (this.originalRuleset == null)
      if (Configuration.errorOnAutoCreate())
        throw new Error("Attempt to auto-create ExplanationOfBenefit.originalRuleset");
      else if (Configuration.doAutoCreate())
        this.originalRuleset = new Coding(); // cc
    return this.originalRuleset;
  }

  public boolean hasOriginalRuleset() {
    return this.originalRuleset != null && !this.originalRuleset.isEmpty();
  }

  /**
   * @param value {@link #originalRuleset} (The style (standard) and version of
   *              the original material which was converted into this resource.)
   */
  public ExplanationOfBenefit setOriginalRuleset(Coding value) {
    this.originalRuleset = value;
    return this;
  }

  /**
   * @return {@link #created} (The date when the enclosed suite of services were
   *         performed or completed.). This is the underlying object with id,
   *         value and extensions. The accessor "getCreated" gives direct access
   *         to the value
   */
  public DateTimeType getCreatedElement() {
    if (this.created == null)
      if (Configuration.errorOnAutoCreate())
        throw new Error("Attempt to auto-create ExplanationOfBenefit.created");
      else if (Configuration.doAutoCreate())
        this.created = new DateTimeType(); // bb
    return this.created;
  }

  public boolean hasCreatedElement() {
    return this.created != null && !this.created.isEmpty();
  }

  public boolean hasCreated() {
    return this.created != null && !this.created.isEmpty();
  }

  /**
   * @param value {@link #created} (The date when the enclosed suite of services
   *              were performed or completed.). This is the underlying object
   *              with id, value and extensions. The accessor "getCreated" gives
   *              direct access to the value
   */
  public ExplanationOfBenefit setCreatedElement(DateTimeType value) {
    this.created = value;
    return this;
  }

  /**
   * @return The date when the enclosed suite of services were performed or
   *         completed.
   */
  public Date getCreated() {
    return this.created == null ? null : this.created.getValue();
  }

  /**
   * @param value The date when the enclosed suite of services were performed or
   *              completed.
   */
  public ExplanationOfBenefit setCreated(Date value) {
    if (value == null)
      this.created = null;
    else {
      if (this.created == null)
        this.created = new DateTimeType();
      this.created.setValue(value);
    }
    return this;
  }

  /**
   * @return {@link #organization} (The Insurer who produced this adjudicated
   *         response.)
   */
  public Reference getOrganization() {
    if (this.organization == null)
      if (Configuration.errorOnAutoCreate())
        throw new Error("Attempt to auto-create ExplanationOfBenefit.organization");
      else if (Configuration.doAutoCreate())
        this.organization = new Reference(); // cc
    return this.organization;
  }

  public boolean hasOrganization() {
    return this.organization != null && !this.organization.isEmpty();
  }

  /**
   * @param value {@link #organization} (The Insurer who produced this adjudicated
   *              response.)
   */
  public ExplanationOfBenefit setOrganization(Reference value) {
    this.organization = value;
    return this;
  }

  /**
   * @return {@link #organization} The actual object that is the target of the
   *         reference. The reference library doesn't populate this, but you can
   *         use it to hold the resource if you resolve it. (The Insurer who
   *         produced this adjudicated response.)
   */
  public Organization getOrganizationTarget() {
    if (this.organizationTarget == null)
      if (Configuration.errorOnAutoCreate())
        throw new Error("Attempt to auto-create ExplanationOfBenefit.organization");
      else if (Configuration.doAutoCreate())
        this.organizationTarget = new Organization(); // aa
    return this.organizationTarget;
  }

  /**
   * @param value {@link #organization} The actual object that is the target of
   *              the reference. The reference library doesn't use these, but you
   *              can use it to hold the resource if you resolve it. (The Insurer
   *              who produced this adjudicated response.)
   */
  public ExplanationOfBenefit setOrganizationTarget(Organization value) {
    this.organizationTarget = value;
    return this;
  }

  /**
   * @return {@link #requestProvider} (The practitioner who is responsible for the
   *         services rendered to the patient.)
   */
  public Reference getRequestProvider() {
    if (this.requestProvider == null)
      if (Configuration.errorOnAutoCreate())
        throw new Error("Attempt to auto-create ExplanationOfBenefit.requestProvider");
      else if (Configuration.doAutoCreate())
        this.requestProvider = new Reference(); // cc
    return this.requestProvider;
  }

  public boolean hasRequestProvider() {
    return this.requestProvider != null && !this.requestProvider.isEmpty();
  }

  /**
   * @param value {@link #requestProvider} (The practitioner who is responsible
   *              for the services rendered to the patient.)
   */
  public ExplanationOfBenefit setRequestProvider(Reference value) {
    this.requestProvider = value;
    return this;
  }

  /**
   * @return {@link #requestProvider} The actual object that is the target of the
   *         reference. The reference library doesn't populate this, but you can
   *         use it to hold the resource if you resolve it. (The practitioner who
   *         is responsible for the services rendered to the patient.)
   */
  public Practitioner getRequestProviderTarget() {
    if (this.requestProviderTarget == null)
      if (Configuration.errorOnAutoCreate())
        throw new Error("Attempt to auto-create ExplanationOfBenefit.requestProvider");
      else if (Configuration.doAutoCreate())
        this.requestProviderTarget = new Practitioner(); // aa
    return this.requestProviderTarget;
  }

  /**
   * @param value {@link #requestProvider} The actual object that is the target of
   *              the reference. The reference library doesn't use these, but you
   *              can use it to hold the resource if you resolve it. (The
   *              practitioner who is responsible for the services rendered to the
   *              patient.)
   */
  public ExplanationOfBenefit setRequestProviderTarget(Practitioner value) {
    this.requestProviderTarget = value;
    return this;
  }

  /**
   * @return {@link #requestOrganization} (The organization which is responsible
   *         for the services rendered to the patient.)
   */
  public Reference getRequestOrganization() {
    if (this.requestOrganization == null)
      if (Configuration.errorOnAutoCreate())
        throw new Error("Attempt to auto-create ExplanationOfBenefit.requestOrganization");
      else if (Configuration.doAutoCreate())
        this.requestOrganization = new Reference(); // cc
    return this.requestOrganization;
  }

  public boolean hasRequestOrganization() {
    return this.requestOrganization != null && !this.requestOrganization.isEmpty();
  }

  /**
   * @param value {@link #requestOrganization} (The organization which is
   *              responsible for the services rendered to the patient.)
   */
  public ExplanationOfBenefit setRequestOrganization(Reference value) {
    this.requestOrganization = value;
    return this;
  }

  /**
   * @return {@link #requestOrganization} The actual object that is the target of
   *         the reference. The reference library doesn't populate this, but you
   *         can use it to hold the resource if you resolve it. (The organization
   *         which is responsible for the services rendered to the patient.)
   */
  public Organization getRequestOrganizationTarget() {
    if (this.requestOrganizationTarget == null)
      if (Configuration.errorOnAutoCreate())
        throw new Error("Attempt to auto-create ExplanationOfBenefit.requestOrganization");
      else if (Configuration.doAutoCreate())
        this.requestOrganizationTarget = new Organization(); // aa
    return this.requestOrganizationTarget;
  }

  /**
   * @param value {@link #requestOrganization} The actual object that is the
   *              target of the reference. The reference library doesn't use
   *              these, but you can use it to hold the resource if you resolve
   *              it. (The organization which is responsible for the services
   *              rendered to the patient.)
   */
  public ExplanationOfBenefit setRequestOrganizationTarget(Organization value) {
    this.requestOrganizationTarget = value;
    return this;
  }

  protected void listChildren(List<Property> childrenList) {
    super.listChildren(childrenList);
    childrenList.add(new Property("identifier", "Identifier", "The Response business identifier.", 0,
        java.lang.Integer.MAX_VALUE, identifier));
    childrenList.add(new Property("request", "Reference(Claim)", "Original request resource reference.", 0,
        java.lang.Integer.MAX_VALUE, request));
    childrenList.add(new Property("outcome", "code", "Transaction status: error, complete.", 0,
        java.lang.Integer.MAX_VALUE, outcome));
    childrenList.add(new Property("disposition", "string", "A description of the status of the adjudication.", 0,
        java.lang.Integer.MAX_VALUE, disposition));
    childrenList.add(new Property("ruleset", "Coding",
        "The version of the style of resource contents. This should be mapped to the allowable profiles for this and supporting resources.",
        0, java.lang.Integer.MAX_VALUE, ruleset));
    childrenList.add(new Property("originalRuleset", "Coding",
        "The style (standard) and version of the original material which was converted into this resource.", 0,
        java.lang.Integer.MAX_VALUE, originalRuleset));
    childrenList.add(
        new Property("created", "dateTime", "The date when the enclosed suite of services were performed or completed.",
            0, java.lang.Integer.MAX_VALUE, created));
    childrenList.add(new Property("organization", "Reference(Organization)",
        "The Insurer who produced this adjudicated response.", 0, java.lang.Integer.MAX_VALUE, organization));
    childrenList.add(new Property("requestProvider", "Reference(Practitioner)",
        "The practitioner who is responsible for the services rendered to the patient.", 0, java.lang.Integer.MAX_VALUE,
        requestProvider));
    childrenList.add(new Property("requestOrganization", "Reference(Organization)",
        "The organization which is responsible for the services rendered to the patient.", 0,
        java.lang.Integer.MAX_VALUE, requestOrganization));
  }

  @Override
  public void setProperty(String name, Base value) throws FHIRException {
    if (name.equals("identifier"))
      this.getIdentifier().add(castToIdentifier(value));
    else if (name.equals("request"))
      this.request = castToReference(value); // Reference
    else if (name.equals("outcome"))
      this.outcome = new RemittanceOutcomeEnumFactory().fromType(value); // Enumeration<RemittanceOutcome>
    else if (name.equals("disposition"))
      this.disposition = castToString(value); // StringType
    else if (name.equals("ruleset"))
      this.ruleset = castToCoding(value); // Coding
    else if (name.equals("originalRuleset"))
      this.originalRuleset = castToCoding(value); // Coding
    else if (name.equals("created"))
      this.created = castToDateTime(value); // DateTimeType
    else if (name.equals("organization"))
      this.organization = castToReference(value); // Reference
    else if (name.equals("requestProvider"))
      this.requestProvider = castToReference(value); // Reference
    else if (name.equals("requestOrganization"))
      this.requestOrganization = castToReference(value); // Reference
    else
      super.setProperty(name, value);
  }

  @Override
  public Base addChild(String name) throws FHIRException {
    if (name.equals("identifier")) {
      return addIdentifier();
    } else if (name.equals("request")) {
      this.request = new Reference();
      return this.request;
    } else if (name.equals("outcome")) {
      throw new FHIRException("Cannot call addChild on a singleton property ExplanationOfBenefit.outcome");
    } else if (name.equals("disposition")) {
      throw new FHIRException("Cannot call addChild on a singleton property ExplanationOfBenefit.disposition");
    } else if (name.equals("ruleset")) {
      this.ruleset = new Coding();
      return this.ruleset;
    } else if (name.equals("originalRuleset")) {
      this.originalRuleset = new Coding();
      return this.originalRuleset;
    } else if (name.equals("created")) {
      throw new FHIRException("Cannot call addChild on a singleton property ExplanationOfBenefit.created");
    } else if (name.equals("organization")) {
      this.organization = new Reference();
      return this.organization;
    } else if (name.equals("requestProvider")) {
      this.requestProvider = new Reference();
      return this.requestProvider;
    } else if (name.equals("requestOrganization")) {
      this.requestOrganization = new Reference();
      return this.requestOrganization;
    } else
      return super.addChild(name);
  }

  public String fhirType() {
    return "ExplanationOfBenefit";

  }

  public ExplanationOfBenefit copy() {
    ExplanationOfBenefit dst = new ExplanationOfBenefit();
    copyValues(dst);
    if (identifier != null) {
      dst.identifier = new ArrayList<Identifier>();
      for (Identifier i : identifier)
        dst.identifier.add(i.copy());
    }
    ;
    dst.request = request == null ? null : request.copy();
    dst.outcome = outcome == null ? null : outcome.copy();
    dst.disposition = disposition == null ? null : disposition.copy();
    dst.ruleset = ruleset == null ? null : ruleset.copy();
    dst.originalRuleset = originalRuleset == null ? null : originalRuleset.copy();
    dst.created = created == null ? null : created.copy();
    dst.organization = organization == null ? null : organization.copy();
    dst.requestProvider = requestProvider == null ? null : requestProvider.copy();
    dst.requestOrganization = requestOrganization == null ? null : requestOrganization.copy();
    return dst;
  }

  protected ExplanationOfBenefit typedCopy() {
    return copy();
  }

  @Override
  public boolean equalsDeep(Base other) {
    if (!super.equalsDeep(other))
      return false;
    if (!(other instanceof ExplanationOfBenefit))
      return false;
    ExplanationOfBenefit o = (ExplanationOfBenefit) other;
    return compareDeep(identifier, o.identifier, true) && compareDeep(request, o.request, true)
        && compareDeep(outcome, o.outcome, true) && compareDeep(disposition, o.disposition, true)
        && compareDeep(ruleset, o.ruleset, true) && compareDeep(originalRuleset, o.originalRuleset, true)
        && compareDeep(created, o.created, true) && compareDeep(organization, o.organization, true)
        && compareDeep(requestProvider, o.requestProvider, true)
        && compareDeep(requestOrganization, o.requestOrganization, true);
  }

  @Override
  public boolean equalsShallow(Base other) {
    if (!super.equalsShallow(other))
      return false;
    if (!(other instanceof ExplanationOfBenefit))
      return false;
    ExplanationOfBenefit o = (ExplanationOfBenefit) other;
    return compareValues(outcome, o.outcome, true) && compareValues(disposition, o.disposition, true)
        && compareValues(created, o.created, true);
  }

  public boolean isEmpty() {
    return super.isEmpty() && (identifier == null || identifier.isEmpty()) && (request == null || request.isEmpty())
        && (outcome == null || outcome.isEmpty()) && (disposition == null || disposition.isEmpty())
        && (ruleset == null || ruleset.isEmpty()) && (originalRuleset == null || originalRuleset.isEmpty())
        && (created == null || created.isEmpty()) && (organization == null || organization.isEmpty())
        && (requestProvider == null || requestProvider.isEmpty())
        && (requestOrganization == null || requestOrganization.isEmpty());
  }

  @Override
  public ResourceType getResourceType() {
    return ResourceType.ExplanationOfBenefit;
  }

  @SearchParamDefinition(name = "identifier", path = "ExplanationOfBenefit.identifier", description = "The business identifier of the Explanation of Benefit", type = "token")
  public static final String SP_IDENTIFIER = "identifier";

}